<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<meta name="viewport"
			content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
		<title>表格操作 - layui</title>
	</head>
	<body>
		<!-- 表顶部自定义按钮组 -->
		<script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container">
				<button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
				<button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
				<button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
				<button class="layui-btn layui-btn-sm" lay-event="reload">重载</button>
			</div>
		</script>

		<h1>表1 - 表样式复杂</h1>
		<table id="test" lay-filter="test"></table>

		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
		</script>

		<script type="text/html" id="usernameTpl">
			<a href="" class="layui-table-link">{{d.username || ''}}</a>
		</script>

		<script type="text/html" id="switchTpl">
			<input type="checkbox" name="yyy" lay-skin="switch" lay-text="女|男">
		</script>

		<script type="text/html" id="cityTpl">
			<select lay-ignore>
				<option value="浙江杭州">浙江杭州</option>
				<option value="江西南昌">江西南昌</option>
				<option value="湖北武汉">湖北武汉</option>
			</select>
		</script>

		<script type="text/html" id="checkboxTpl">
			<input type="checkbox" name="" title="锁定" checked>
		</script>

		<script type="text/html" id="LAY_table_tpl_email">
			<span {{# if(!d.activate){ }}style="color:#999" {{# } }}>{{ d.email }}</span>
		</script>

		<h1>表2 - 表样式简单</h1>
		<table id="test2" lay-filter="test2"></table>

		<h1>表3 - 表样式写在HTML</h1>
		<table class="layui-table"
			lay-data="{url:'/task/tableData?name=demo2.json', toolbar: '#toolbarDemo', page: true, limit: 6}">
			<thead>
				<tr>
					<th lay-data="{field:'username'}" rowspan="3">联系人</th>
					<th lay-data="{field:'amount', width:120,hide:1}" rowspan="3">金额</th>
					<th lay-data="{align:'center'}" colspan="5">地址1</th>
					<th lay-data="{align:'center'}" colspan="2">地址2</th>
					<th lay-data="{fixed: 'right', width: 120, align: 'center', toolbar: '#barDemo'}" rowspan="3">操作
					</th>
				</tr>
				<tr>
					<th lay-data="{field:'province', width:120,hide:1}" rowspan="2">省</th>
					<th lay-data="{field:'city', width:80,hide:1}" rowspan="2">市</th>
					<th lay-data="{align:'center'}" colspan="2">详细</th>
					<th lay-data="{field:'zone'}" rowspan="2">区</th>
					<th lay-data="{field:'province', width:80}" rowspan="2">省</th>
					<th lay-data="{field:'city', width:80}" rowspan="2">市</th>
				</tr>
				<tr>
					<th lay-data="{field:'address', width:120,hide:1}">小区</th>
					<th lay-data="{field:'house', width:150,hide:1}">单元</th>
				</tr>
			</thead>
		</table>

		<h1>表4 - 直接赋值数据</h1>
		<table id="demo"></table>

		<div class="layui-btn-group">
			<button class="layui-btn" data-type="parseTable">转化为数据表格</button>
		</div>

		<h1>表5</h1>
		<table class="layui-table" lay-skin="line" lay-filter="parse-table-demo">
			<thead>
				<tr>
					<th lay-data="{checkbox:true}"></th>
					<th lay-data="{field:'username', width:200}">昵称</th>
					<th lay-data="{field:'joinTime', width:150}">加入时间</th>
					<th lay-data="{field:'sign'}">签名</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td></td>
					<td>贤心1</td>
					<td>2016-11-28</td>
					<td>人生就像是一场修行a</td>
				</tr>
				<tr>
					<td></td>
					<td>贤心2</td>
					<td>2016-11-29</td>
					<td>人生就像是一场修行b</td>
				</tr>
				<tr>
					<td></td>
					<td>贤心3</td>
					<td>2016-11-30</td>
					<td>人生就像是一场修行c</td>
				</tr>
			</tbody>
		</table>

		<table class="layui-table" lay-filter="parse-table-demo">
			<thead>
				<tr>
					<td rowspan="2" lay-data="{field:'louceng'}">楼层</td>
					<td colspan="2">1单元</td>
					<td colspan="2">2单元</td>
				</tr>
				<tr>
					<td lay-data="{field:'men1', width:80}">1门</td>
					<td lay-data="{field:'men2', width:80}">2门</td>
					<td lay-data="{field:'men3', width:80}">1门</td>
					<td lay-data="{field:'men4', width:80}">2门</td>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td>3楼</td>
					<td>301</td>
					<td>302</td>
					<td>301</td>
					<td>302</td>
				</tr>
				<tr>
					<td>2楼</td>
					<td>201</td>
					<td>202</td>
					<td>201</td>
					<td>202</td>
				</tr>
				<tr>
					<td>1楼</td>
					<td>101</td>
					<td>102</td>
					<td>101</td>
					<td>102</td>
				</tr>
			</tbody>
		</table>

		<script src="/static/layui/lay/modules/table.js"></script>
		<script>
            layui.use('table', function() {
            var table = layui.table;
            window.ins1 = table.render({
            elem: '#test',
            height: 400, // 定义高度后，表格超过出现滚动，没有时顶部空白
            //,width: 600
            title: '用户数据表',
            url: '/task/tableData?name=demo.json',
            page: {},
            autoSort: false,
            totalRow: true, // 顶部按钮 -> 筛选，导出，打印
            limit: 30,
            toolbar: '#toolbarDemo', // 自定义顶部按钮组
            defaultToolbar: ['filter', 'exports', 'print', {
            title: '帮助',
            layEvent: 'LAYTABLE_TIPS',
            icon: 'layui-icon-tips'
            }],
            cols: [
            [{
            type: 'checkbox',
            fixed: 'left'
            }, {
            field: 'id',
            title: 'ID',
            width: 80,
            fixed: 'left',
            unresize: true,
            sort: true,
            totalRowText: '合计：'
            }, {
            field: 'username',
            title: '用户名',
            width: 120,
            edit: 'text',
            templet: '#usernameTpl'
            }, {
            field: 'email',
            title: '邮箱',
            hide: 0,
            width: 150,
            edit: 'text',
            templet: function(d) {
            return '</script>
	</body>
</html>
